package com.ruoyi.system.service.gallery.impl;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.system.domain.gallery.GalleryInfo;
import com.ruoyi.system.domain.gallery.GalleryOriginal;
import com.ruoyi.system.domain.zhuangxiumain.shopMain.SupplierInfo;
import com.ruoyi.system.mapper.gallery.GalleryInfoMapper;
import com.ruoyi.system.mapper.gallery.GalleryOriginalMapper;
import com.ruoyi.system.mapper.zhuangxiumapper.shopMapper.SupplierInfoMapper;
import com.ruoyi.system.service.gallery.GalleryInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 图库Service业务层处理
 *
 * @author 张少丛
 * @date 2020-11-30
 */
@Service
public class GalleryInfoServiceImpl implements GalleryInfoService
{
    @Autowired
    private GalleryInfoMapper galleryInfoMapper;

    @Autowired
    private SupplierInfoMapper supplierInfoMapper;

    /**
     * 查询图库
     *
     * @param galleryInfoId 图库ID
     * @return 图库
     */
    @Override
    public GalleryInfo selectGalleryInfoById(Long galleryInfoId)
    {
        return galleryInfoMapper.selectGalleryInfoById(galleryInfoId);
    }

    /**
     * 查询图库列表
     *
     * @param galleryInfo 图库
     * @return 图库
     */
    @Override
    public List<GalleryInfo> selectGalleryInfoList(GalleryInfo galleryInfo,Long userId)
    {
        SupplierInfo supplierInfo = new SupplierInfo();
        supplierInfo.setCustomerId(userId);
        // 创建集合储存供应商ID
        List<Long> supplierIds = new ArrayList<Long>();
        // 根据用户ID查询供应商信息
        List<SupplierInfo> supplierInfoList = supplierInfoMapper.selectSupplierInfoByUserIdOne(supplierInfo);
        if(supplierInfoList.size()>0){
            for (SupplierInfo supplier : supplierInfoList) {
                supplierIds.add(Long.valueOf(supplier.getSupplierId()));
            }
        }else{
            supplierIds.add(Long.valueOf(-1));
        }
        galleryInfo.setSupplierIds(supplierIds);
        return galleryInfoMapper.selectGalleryInfoList(galleryInfo);
    }

    /**
     * 新增图库
     *
     * @param galleryInfo 图库
     * @return 结果
     */
    @Override
    public int insertGalleryInfo(GalleryInfo galleryInfo)
    {
        return galleryInfoMapper.insertGalleryInfo(galleryInfo);
    }

    /**
     * 修改图库
     *
     * @param galleryInfo 图库
     * @return 结果
     */
    @Override
    public int updateGalleryInfo(GalleryInfo galleryInfo)
    {
        return galleryInfoMapper.updateGalleryInfo(galleryInfo);
    }

    /**
     * 批量删除图库
     *
     * @param galleryInfoIds 需要删除的图库ID
     * @return 结果
     */
    @Override
    public int deleteGalleryInfoByIds(Long[] galleryInfoIds)
    {
        return galleryInfoMapper.deleteGalleryInfoByIds(galleryInfoIds);
    }

    /**
     * 删除图库信息
     *
     * @param galleryInfoId 图库ID
     * @return 结果
     */
    @Override
    public int deleteGalleryInfoById(Long galleryInfoId)
    {
        return galleryInfoMapper.deleteGalleryInfoById(galleryInfoId);
    }

    /**
     * 查询店铺列表
     * @return
     */
    public List<SupplierInfo> selectSupplierList(Long userId){
        SupplierInfo supplierInfo = new SupplierInfo();
        supplierInfo.setCustomerId(userId);
        // 创建集合储存供应商ID
        List<Long> supplierIds = new ArrayList<Long>();
        // 根据用户ID查询供应商信息
        List<SupplierInfo> supplierInfoList = supplierInfoMapper.findAllSupplierInfo(supplierInfo);
        for (SupplierInfo supplier : supplierInfoList) {
            supplierIds.add(Long.valueOf(supplier.getSupplierId()));
        }
        return supplierInfoList;
    }

}
